{{csrf_field()}}
<div  class="layui-form">

    <div class="layui-form-item">
        <label class="layui-form-label">小程序名称：</label>
        <div class="layui-input-block">
            <input type="text" name="name" value="{{$info->name ?? ''}}" lay-verify="required"  lay-reqText="名称必填"placeholder="请输入用户名" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">类型：</label>
        <div class="layui-input-block">
            <select  name="type" xm-select-direction="down" xm-select="select1" xm-select-search-type="dl" xm-select-search xm-select-radio="">
                @foreach(mini_program_list() as $key =>$val)
                    <option value="{{$key}}" @if(isset($checkArrR) && in_array($val['id'],$checkArrR)) selected @endif>{{$val}}</option>
                @endforeach
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">AppId：</label>
        <div class="layui-input-block">
            <input type="text" name="app_id" value="{{$info->app_id ?? ''}}"  placeholder="输入AppId" autocomplete="off" class="layui-input">
            <div class="layui-form-mid layui-word-aux">请至微信小程序平台 设置》开发设置 中复制粘贴过来</div>

        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">AppSecret：</label>
        <div class="layui-input-block">
            <input type="text" name="app_secret" value="{{$info->app_secret ?? ''}}"  placeholder="输入AppSecret" autocomplete="off" class="layui-input">
            <div class="layui-form-mid layui-word-aux">请至微信小程序平台 设置》开发设置 中复制粘贴过来</div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">原始Id：</label>
        <div class="layui-input-block">
            <input type="text" name="wx_user_name" value="{{$info->user_name ?? ''}}"  placeholder="输入密码" autocomplete="off" class="layui-input">
            <div class="layui-form-mid layui-word-aux">请至微信小程序平台 设置》开发设置 中复制粘贴过来</div>

        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">主体信息：</label>
        <div class="layui-input-block">
            <input type="text" name="principal_name" value="{{$info->principal_name ?? ''}}"  placeholder="输入密码" autocomplete="off" class="layui-input">
            <div class="layui-form-mid layui-word-aux">请至微信小程序平台 设置》开发设置 中复制粘贴过来</div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">简介：</label>
        <div class="layui-input-block">
            <textarea name="description" placeholder="简介" class="layui-textarea custom_key_val"></textarea>
            <div class="layui-form-mid layui-word-aux"></div>

        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">微信商户号id：</label>
        <div class="layui-input-block">
            <input type="text" name="mchid" value="{{$info->mchid ?? ''}}"  placeholder="输入密码" autocomplete="off" class="layui-input">
            <div class="layui-form-mid layui-word-aux">请至微信小程序平台 设置》开发设置 中复制粘贴过来</div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商户支付：</label>
        <div class="layui-input-block">
            <input type="text" name="api_key" value="{{$info->api_key ?? ''}}"  placeholder="输入密码" autocomplete="off" class="layui-input">
            <div class="layui-form-mid layui-word-aux"></div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">分享标题：</label>
        <div class="layui-input-block">
            <input type="text" name="share_title" value="{{$info->share_title ?? ''}}"  placeholder="输入密码" autocomplete="off" class="layui-input">
            <div class="layui-form-mid layui-word-aux"></div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">分享描述：</label>
        <div class="layui-input-block">
            <textarea name="share_desc" placeholder="分享描述" class="layui-textarea custom_key_val">{{$info->share_desc ?? ''}}</textarea>
            <div class="layui-form-mid layui-word-aux"></div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">图片</label>
        <div class="layui-input-block">

            <select lay-verify="required" lay-reqText="请选择分类" name="roles_id" xm-select-direction="down" xm-select="roles_id" xm-select-search-type="dl" xm-select-search>
                @if(isset($roles))
                    @foreach($roles as $key =>$val)
                        <option value="{{$val['id']}}" @if(isset($checkArrR) && in_array($val['id'],$checkArrR)) selected @endif>{{$val['name']}}</option>
                    @endforeach
                @endif
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label ">封面</label>
        <div class="layui-input-block">
            <button type="button"  class="layui-btn upload-image">上传图片</button>
            <div class="layui-upload-list">

                @if(isset($info->image_id) && !empty($info->image_id))
                    <img class="layui-upload-img" src="{{$info->image_id?? ''}}" style="width: 90px" >
                @else
                    <img class="layui-upload-img" style="width: 90px" >
                @endif
                <input type="hidden" name="image_id" value="{{$info->image_id?? ''}}">
            </div>

        </div>
    </div>



    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-filter="post-submit" lay-submit>保 存</button>
        </div>
    </div>
  </div>
<textarea id="edit_image" style="display: none;"></textarea>
@section('script')
    <link rel="stylesheet" href="{{ asset('static/admin/css/formSelects-v4.css') }}">
    <script>
        layui.use(['layer', 'form','jquery','formSelects'], function(){
            var layer = layui.layer,
                form =layui.form,

                $  = layui.jquery;

            var _editor = UE.getEditor("edit_image",{
                initialFrameWidth:800,
                initialFrameHeight:300,
                zIndex:19891026,
            });
            _editor.ready(function (){
                _editor.hide();
                _editor.addListener('beforeInsertImage',function(t,arg){
                    console.log(arg);
                    console.log(t);
                    var obj = _editor.queryCommandValue("serverparam");
                    if(obj.type == "upload-image"){
                        if(arg.length>1){
                            layer.msg("最多只能选择1张图片，请重新选择");
                            return false;
                        }
                        if(arg.length>0) {
                            var uploadImageTd = obj.uploadImageItem.parent().find(".layui-upload-list");
                            console.log(uploadImageTd);
                            uploadImageTd.find('img').attr('src',arg[0].src);
                            uploadImageTd.find('input').val(arg[0].image_id);
                            uploadImageTd.show();
                        }else{
                            layer.msg("请先选择图片");
                            return false;
                        }
                    }
                    return true;
                });
            });

            $("body").on("click", ".upload-image", function () {

                //此处进行初始化
                var obj = _editor.queryCommandValue("serverparam");
                obj.type = "upload-image";
                obj.uploadImageItem = $(this);
                var uploadImage = _editor.getDialog("insertimage");
                console.log(obj);
                uploadImage.open();
            });
            //监听提交
            form.on('submit(post-submit)', function(data){

            });
        });
    </script>
@endsection